<script setup>
import { useRoute, useRouter } from 'vue-router'
import { computed } from 'vue'

const route = useRoute()
const router = useRouter()
const active = computed(() => route.path)
const showNav = computed(() => route.path !== '/login')
const onSelect = (index) => {
  router.push(index)
}
const logout = () => {
  localStorage.removeItem('token')
  window.location.href = '/login'
}
</script>

<template>
  <el-container class="main-layout">
    <el-header v-if="showNav">
      <div class="nav-bar">
        <div class="logo-area">
          <span class="logo-icon">📚</span>
          <span class="logo-title">图书管理系统</span>
        </div>
        <el-menu :default-active="active" mode="horizontal" @select="onSelect" class="nav-menu" :ellipsis="false">
          <el-menu-item index="/borrower">借书人管理</el-menu-item>
          <el-menu-item index="/book">图书管理</el-menu-item>
          <el-menu-item index="/borrow">借阅办理</el-menu-item>
          <el-menu-item index="/fine">罚款结算</el-menu-item>
        </el-menu>
        <el-button class="logout-btn" type="danger" @click="logout">退出登录</el-button>
      </div>
    </el-header>
    <el-main>
      <router-view />
    </el-main>
  </el-container>
</template>

<style>
html, body, #app {
  width: 100vw;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.main-layout {
  width: 100vw;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background: #f5f6fa;
}
.el-header {
  background: #fff;
  color: #222;
  padding: 0;
  box-shadow: 0 2px 12px rgba(255, 255, 255, 0.13);
  border-radius: 0 0 16px 16px;
  height: 64px;
  display: flex;
  align-items: center;
  z-index: 10;
}
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  width: 100vw;
}
.logo-area {
  display: flex;
  align-items: center;
  margin-left: 32px;
  margin-right: 24px;
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 2px;
  color: #409EFF;
  user-select: none;
}
.logo-icon {
  font-size: 28px;
  margin-right: 8px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.08));
}
.logo-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 1px;
}
.nav-menu {
  background: transparent;
  color: #222;
  border: none;
  flex: 1;
  font-size: 17px;
  --el-menu-item-height: 64px;
}
.el-menu-item {
  border-radius: 10px !important;
  margin: 0 10px;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  font-size: 16px;
  padding: 0 22px !important;
  color: #222 !important;
}
.el-menu-item:hover {
  background: #e6f0fa !important;
  color: #409EFF !important;
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.13);
  transform: translateY(-2px) scale(1.04);
}
.el-menu-item.is-active {
  color: #fff !important;
  background: linear-gradient(90deg, #ffffff 0%, #ffffff 100%) !important;
  border-radius: 10px !important;
  font-weight: bold;
  box-shadow: 0 2px 12px rgba(255, 255, 255, 0.13);
  transform: translateY(-2px) scale(1.08);
  transition: all 0.3s;
}
.el-menu-item.is-active * {
  color: #fff !important;
}
.el-menu--horizontal .el-menu-item.is-active,
.el-menu--horizontal .el-menu-item.is-active span,
.el-menu--horizontal .el-menu-item.is-active a {
  color: #fff !important;
}
.logout-btn {
  margin-right: 40px;
  margin-left: 32px;
  float: right;
  border-radius: 10px;
  font-size: 16px;
  height: 40px;
  box-shadow: 0 2px 12px rgba(255,0,0,0.10);
  font-weight: 500;
  letter-spacing: 1px;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.logout-btn:hover {
  background: #ff7875 !important;
  color: #fff !important;
  box-shadow: 0 4px 16px rgba(255,0,0,0.13);
}
</style>
